package unclassified.simple;

import java.util.Map;
import java.util.PriorityQueue;
import java.util.TreeMap;

public class MaximizeSumOfArrayAfterKNegations_1005 {
    public int largestSumAfterKNegations(int[] nums, int k) {

        PriorityQueue<Integer> queue = new PriorityQueue<>((a, b) -> nums[a] - nums[b]);
        for (int i = 0; i < nums.length; i++) {
            queue.offer(i);
        }
        while (k-- > 0) {
            Integer poll = queue.poll();
            nums[poll] = -nums[poll];
            queue.offer(poll);
        }

        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            res += nums[i];
        }
        return res;
    }

    public static void main(String[] args) {
        MaximizeSumOfArrayAfterKNegations_1005 mm = new MaximizeSumOfArrayAfterKNegations_1005();
        mm.largestSumAfterKNegations(new int[]{4, 2, 3}, 1);
    }
}
